// 最后一个属性是数组 / a -> obj, b -> target
// example: _jsonArray(obj, target, 'a', 'b');
// 等同于: target['a']['b'].push(obj);
const jsonArray = function(a, b) {
	for (var i = 2, l = arguments.length - 1; i < l; i ++)
		b = b[arguments[i]] || (b[arguments[i]] = {});
	(b[arguments[l]] || (b[arguments[l]] = [])).push(a);
	return b[arguments[l]];
}

// example: _jsonChain(obj, target, 'a', 'b');
// 等同于: target['a']['b'] = obj;
const jsonChain = function(a, b) {
	for (var i = 2, l = arguments.length - 1, c = b; i < l; i ++)
		c = c[arguments[i]] || (c[arguments[i]] = {});
	c[arguments[l]] = a;
	return c;
}

export {jsonArray, jsonChain}